<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="160px">

      <el-form-item label="计划编号" prop="planNo">
        <el-input
          v-model="queryParams.planNo"
          placeholder="请输入"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <el-form-item label="计划开始时间" prop="planStartDate">
        <el-date-picker clearable
          v-model="queryParams.planStartDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="计划结束时间" prop="planEndDate">
        <el-date-picker clearable
          v-model="queryParams.planEndDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="作业组织（建管）单位" prop="jobGroupName">
        <el-input
          v-model="queryParams.jobGroupName"
          placeholder="请输入"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电压等级" prop="voltageLevel">
        <el-select
          v-model="queryParams.voltageLevel"
          placeholder="请选择"
          clearable
          style="width: 200px"
        >
          <el-option
            v-for="dict in dl_voltage_level"
            :key="dict.label"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>

 
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
        >导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="treatmentList">
      <el-table-column label="作业组织（建管）单位" align="center" prop="jobGroupName" />
      <el-table-column label="工作负责人" align="center" prop="workHeaderName" />
      <el-table-column label="电压等级" align="center" prop="voltageLevel" />
      <el-table-column label="计划开始时间" align="center" prop="planStartDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.planStartDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="治理完成截止时间" align="center" prop="governanceFinishEndDate" width="180">
        <template #default="scope">
          <span style="color:red">{{ parseTime(scope.row.governanceFinishEndDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划编号" align="center" prop="planNo" />
      <el-table-column label="超期天数" align="center" prop="overdueDays">
        <template #default="scope">
          <span style="color:red" v-if="scope.row.overdueDays > 0">{{ scope.row.overdueDays }}</span>
          <span v-else>{{ scope.row.overdueDays }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工单状态" align="center" prop="statusDesc">
        <template #default="scope">
          <span style="color:red" v-if="scope.row.overdueDays >= 3">{{ scope.row.statusDesc }}</span>
          <span v-else>{{ scope.row.statusDesc }}</span>
        </template>
      </el-table-column>

      <el-table-column label="作业风险等级" align="center" prop="jobRiskLevel" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button
            type="text"
            @click="handleLook(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" v-model="open" width="800px" append-to-body>
      <el-form ref="treatmentRef" :model="form" :rules="rules" label-width="160px">
        <el-form-item label="作业组织（建管）单位" prop="jobGroupName">
          <el-input v-model="form.jobGroupName" placeholder="请输入" :disabled="true"/>
        </el-form-item>
        <el-form-item label="电压等级" prop="voltageLevel">
          <el-input v-model="form.voltageLevel" placeholder="请输入" :disabled="true"/>
        </el-form-item>
        <el-form-item label="作业风险等级" prop="jobRiskLevel">
          <el-input v-model="form.jobRiskLevel" placeholder="请输入" :disabled="true"/>
        </el-form-item>
        <el-form-item label="电网风险等级" prop="powerGridRiskLevel">
          <el-input v-model="form.powerGridRiskLevel" placeholder="请输入" :disabled="true"/>
        </el-form-item>
        <el-form-item label="工作负责人" prop="workHeaderName">
          <el-input v-model="form.workHeaderName" placeholder="请输入" :disabled="true"/>
        </el-form-item>
        <el-form-item label="计划开始时间" prop="planStartDate">
          <el-date-picker clearable
            v-model="form.planStartDate"
            type="datetime"
            value-format="YYYY-MM-DD HH:mm:ss"
            placeholder="请选择计划开始时间" :disabled="true">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="治理完成截止时间" prop="governanceFinishEndDate">
          <el-date-picker clearable
            v-model="form.governanceFinishEndDate"
            type="datetime"
            value-format="YYYY-MM-DD HH:mm:ss"
            placeholder="" :disabled="true">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="作业内容">
          <div class="ql-editor"  v-html="form.iobContent"></div>
        </el-form-item>
        <el-form-item label="计划编号" prop="planNo">
          <el-input v-model="form.planNo" placeholder="请输入" :disabled="true" />
        </el-form-item>
        <el-form-item label="工单编号" prop="workOrderNo">
          <el-input v-model="form.workOrderNo" placeholder="请输入" :disabled="true" />
        </el-form-item>
        <el-form-item label="超期天数" prop="overdueDays">
          <el-input v-model="form.overdueDays" placeholder="请输入" :disabled="true"/>
        </el-form-item>
        <el-form-item label="工单状态" prop="statusDesc">
          <el-input v-model="form.statusDesc" placeholder="请输入" :disabled="true"/>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Treatment">
import { listTreatment, getTreatment, delTreatment, addTreatment, updateTreatment } from "@/api/platform/treatment";

const { proxy } = getCurrentInstance();
const {
  dl_voltage_level,
  dl_job_risk_level,
  dl_power_grid_risk_level,
  dl_job_type,
  dl_plan_status,
} = proxy.useDict(
  "dl_voltage_level",
  "dl_job_risk_level",
  "dl_power_grid_risk_level",
  "dl_job_type",
  "dl_plan_status"
);

const treatmentList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    jobGroupId: null,
    jobGroupName: null,
    voltageLevel: null,
    jobRiskLevel: null,
    powerGridRiskLevel: null,
    jobType: null,
    workHeaderName: null,
    planStartDate: null,
    planEndDate: null,
    iobContent: null,
    planNo: null,
    planStatus: null,
    isDelete: null,
    createId: null,
    updateId: null,
    workOrderId: null,
    workOrderStatus: null,
    workOrderNo: null,
    workOrderStatusName: null
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询【请填写功能名称】列表 */
function getList() {
  loading.value = true;
  listTreatment(queryParams.value).then(response => {
    treatmentList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    jobGroupId: null,
    jobGroupName: null,
    voltageLevel: null,
    jobRiskLevel: null,
    powerGridRiskLevel: null,
    jobType: null,
    workHeader: null,
    workHeaderName: null,
    planStartDate: null,
    planEndDate: null,
    iobContent: null,
    planNo: null,
    planStatus: "0",
    isDelete: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    remark: null,
    createId: null,
    updateId: null,
    workOrderId: null,
    workOrderStatus: 0,
    workOrderNo: null,
    workOrderStatusName: null
  };
  proxy.resetForm("treatmentRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}



/** 查看按钮操作 */
function handleLook(row) {
  reset();
  const _id = row.id || ids.value
  getTreatment(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "查看";
  });
}



/** 导出按钮操作 */
function handleExport() {
  proxy.download('platform/treatment/export', {
    ...queryParams.value
  }, `treatment_${new Date().getTime()}.xlsx`)
}

getList();
</script>
